<template>
  <div>
      <FormPanel
        :style="{
          'margin-bottom':'60px'
        }"
        ref="formPanel"
        :list="formList"
        :cols="2"
        labelWidth='100'
        :isSubmitBtn="false"
        :formType="'new'"
        @formChange="formChangeHandle"
      />
      <div class="upWard" :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }">
      <el-button size="small" type="primary" @click="saveFunc">保存</el-button>
			<el-button size="small" @click="closeDialog">返回</el-button>
		</div>
  </div>
</template>
<script>
import { programInsert } from '@/api/retail/basedata/maintenance'
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'AddPrograms',
  mixins: [dictionary],
  data(){
    return {
      formList: this.createFormList()
    }
  },
  methods: {
    saveFunc () {
      this.$refs.formPanel.SUBMIT_FORM();
      let params = Object.assign({},this.saveData)
      params.serviceType = params.serviceType.toString()
      programInsert(params).then(res => {
        if (res.success) {
          this.closeDialog('refresh')
        }
      })
    },
    createFormList () {
      return [
        {
          type: 'INPUT',
          label: '项目代码',
          fieldName: 'serviceCode',
          offsetRightCols: 1,
          placeholder: '',
          rules: [{ required: true, message: '请填项目代码', trigger: 'blur' },
                  // { pattern: /^([0-9A-Za-z]){1,6}$/, message: '至多6位字母或数字' }],
                  { pattern: /^(?=.*\d)(?=.*[a-zA-Z])[0-9A-Za-z]{1,6}$/, message: '至多6位字母+数字' }],
        },
        {
          type: 'INPUT',
          label: '项目名称',
          fieldName: 'serviceName',
          offsetRightCols: 1,
          placeholder: '',
          rules: [{ required: true, message: '请填项目名称', trigger: 'blur' },
                  { pattern: /^([\w|\W]){1,6}$/, message: '至多6个字符' }],
        },
        {
          type: 'SELECT',
          label: '费用类型',
          fieldName: 'serviceType',
          offsetRightCols: 1,
          placeholder: '请选择',
          rules: [{ required: true, message: '请填费用类型', trigger: 'blur' }],
          itemList: this.createDictList('1421'),
        },
        {
          type: 'INPUT_NUMBER',
          label: '费用金额',
          fieldName: 'directivePrice',
          offsetRightCols: 1,
          placeholder: '',
        },

      ]
    },
    closeDialog (val='') {
      this.$emit('close', val)
    },
    formChangeHandle(val) {
      this.saveData = _.cloneDeep(val);
    },
  }
}
</script>
<style lang="less" scoped>

</style>
